﻿#ifndef XFGRABER_H
#define XFGRABER_H

//#include "stdafx.h"
#include "xfccm.h"
#include "imagekit.h"
#include <QObject>

#include "errorHandling/errorreporter.h"
#include "errorHandling/silicolerror.h"
#include "iniparser.h"
#include "minwindef.h"

using namespace XF;

class XfGraber : public QObject
{
    Q_OBJECT
public:
    XfGraber();
    bool enumerateDevice();
    bool openDevice();
    bool closeDevice();
    bool loadIniFile();
    bool startCamera();
    void openSensorPower();
    bool readSensorID(SensorTab *pSensorTab);

    Q_PROPERTY(QString currentSensorID READ currentSensorID WRITE setCurrentSensorID NOTIFY currentSensorIDChanged)
    struct CameraChannel
    {
        CameraChannel()
            : m_iDevID(-1)
            , m_fMclk(12.0f)
            , m_fAvdd(2.8f)
            , m_fDovdd(1.8f)
            , m_fDvdd(1.5f)
            , m_fAfvcc(0.028f)
            , m_vpp(0.0f)
            , m_uFocusPos(0)
        {}

        bool CloseCameraChannel();
        SensorTab current_sensor;
        char* m_charCurrentDevice;
        int m_iDevID;
        ULONG m_GrabSize;
        float m_fMclk;
        float m_fAvdd;
        float m_fDovdd;
        float m_fDvdd;
        float m_fAfvcc;
        float m_vpp;
        UINT m_uFocusPos;
        float m_fFrameFps;
        int m_iFrameErr;
        int m_iFrameCnt;
    };
    QString currentSensorID() const
    {
        return m_currentSensorID;
    }

public slots:
    void setCurrentSensorID(QString currentSensorID)
    {
        if (m_currentSensorID == currentSensorID)
            return;

        m_currentSensorID = currentSensorID;
        emit currentSensorIDChanged(m_currentSensorID);
    }

signals:
    void currentSensorIDChanged(QString currentSensorID);

private:
    CameraChannel m_CameraChannel;
    bool isInitDevice = false;

    char *DeviceName[4];
    std::string iniFilename;

    QString m_IniFilename;

    bool isGrabbing = false;
    QString m_currentSensorID = "";
    SensorTab *m_SensorTab = NULL;
    ULONG m_bufLen;
};

#endif // XFGRABER_H
